home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / launchpadbugs / html_blueprint.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  16.5 KB  |  454 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. import libxml2
  6. from blueprintbase import LPBluePrint
  7. from lphelper import _gen_getter, user, unicode_for_libxml2
  8. from lptime import LPTime
  9. from bugbase import LPBugInfo
  10. from subscribersbase import LPSubscribers
  11.  
  12. def _get_content(xml, path):
  13.     x = xml.xpathEval(path)
  14.     if not x:
  15.         raise AssertionError
  16.     res = x[0].content.strip('\n ')
  17.     x = res.split('\n')
  18.     return res
  19.  
  20.  
  21. def _get_user(xml, path):
  22.     m = xml.xpathEval(path)
  23.     if m:
  24.         return user.parse_html_user(m[0])
  25.     m = xml.xpathEval('td')
  26.     if not m:
  27.         raise AssertionError
  28.     if not 'None' in m[0].content:
  29.         raise AssertionError
  30.     return user(None)
  31.  
  32.  
  33. class InfoBox(object):
  34.     
  35.     def __init__(self, xml):
  36.         self.xmldoc = xml[0]
  37.         self.parsed = False
  38.         self._InfoBox__priority = None
  39.         self._InfoBox__status = None
  40.         self._InfoBox__delivery = None
  41.         self._InfoBox__goal = None
  42.         self._InfoBox__assignee = user(None)
  43.         self._InfoBox__drafter = user(None)
  44.         self._InfoBox__approver = user(None)
  45.         self._InfoBox__sprints = set()
  46.  
  47.     
  48.     def parse(self):
  49.         if self.parsed:
  50.             return True
  51.         rows = self.xmldoc.xpathEval('tr')
  52.         for row in rows:
  53.             if row.xpathEval('th[contains(.,"Priority")]'):
  54.                 if not not (self._InfoBox__priority):
  55.                     raise AssertionError
  56.                 self._InfoBox__priority = _get_content(row, 'td')
  57.                 continue
  58.             not (self._InfoBox__priority)
  59.             if row.xpathEval('th[contains(.,"Definition")]'):
  60.                 if not not (self._InfoBox__status):
  61.                     raise AssertionError
  62.                 self._InfoBox__status = _get_content(row, 'td')
  63.                 continue
  64.             not (self._InfoBox__status)
  65.             if row.xpathEval('th[contains(.,"Implementation")]'):
  66.                 if not not (self._InfoBox__delivery):
  67.                     raise AssertionError
  68.                 self._InfoBox__delivery = _get_content(row, 'td')
  69.                 continue
  70.             not (self._InfoBox__delivery)
  71.             if row.xpathEval('th[contains(.,"Series goal")]'):
  72.                 if not not (self._InfoBox__goal):
  73.                     raise AssertionError
  74.                 self._InfoBox__goal = _get_content(row, 'td')
  75.                 continue
  76.             not (self._InfoBox__goal)
  77.             if row.xpathEval('th[contains(.,"Assignee")]'):
  78.                 if not not (self._InfoBox__assignee):
  79.                     raise AssertionError
  80.                 self._InfoBox__assignee = _get_user(row, 'td/a')
  81.                 continue
  82.             not (self._InfoBox__assignee)
  83.             if row.xpathEval('th[contains(.,"Drafter")]'):
  84.                 if not not (self._InfoBox__drafter):
  85.                     raise AssertionError
  86.                 self._InfoBox__drafter = _get_user(row, 'td/a')
  87.                 continue
  88.             not (self._InfoBox__drafter)
  89.             if row.xpathEval('th[contains(.,"Approver")]'):
  90.                 if not not (self._InfoBox__approver):
  91.                     raise AssertionError
  92.                 self._InfoBox__approver = _get_user(row, 'td/a')
  93.                 continue
  94.             not (self._InfoBox__approver)
  95.             if row.xpathEval('th[contains(.,"Sprints")]'):
  96.                 m = row.xpathEval('td//a')
  97.                 for i in m:
  98.                     self._InfoBox__sprints.add(i.content)
  99.                 
  100.             self.parsed
  101.             if not None:
  102.                 raise AssertionError, 'unknown attribute in InfoBox: %s' % row.xpathEval('th').content
  103.         
  104.         self.parsed = True
  105.  
  106.     
  107.     def priority(self):
  108.         return self._InfoBox__priority
  109.  
  110.     priority = property(priority)
  111.     
  112.     def status(self):
  113.         return self._InfoBox__status
  114.  
  115.     status = property(status)
  116.     
  117.     def delivery(self):
  118.         return self._InfoBox__delivery
  119.  
  120.     delivery = property(delivery)
  121.     
  122.     def assignee(self):
  123.         return self._InfoBox__assignee
  124.  
  125.     assignee = property(assignee)
  126.     
  127.     def drafter(self):
  128.         return self._InfoBox__drafter
  129.  
  130.     drafter = property(drafter)
  131.     
  132.     def approver(self):
  133.         return self._InfoBox__approver
  134.  
  135.     approver = property(approver)
  136.     
  137.     def sprints(self):
  138.         return self._InfoBox__sprints
  139.  
  140.     sprints = property(sprints)
  141.  
  142.  
  143. class Subscribers(LPSubscribers):
  144.     
  145.     def __init__(self, xml):
  146.         self.parsed = False
  147.         self.xmldoc = xml
  148.         LPSubscribers.__init__(self, ('essential', 'inessential'))
  149.  
  150.     
  151.     def parse(self):
  152.         if self.parsed:
  153.             return True
  154.         for i in self.xmldoc:
  155.             m = i.xpathEval('a')
  156.             if not m:
  157.                 raise AssertionError
  158.             x = user.parse_html_user(m[0])
  159.             m = i.xpathEval('img')
  160.             if not m:
  161.                 raise AssertionError
  162.             if 'inessential' in m[0].prop('src'):
  163.                 self['inessential'].add(x)
  164.                 continue
  165.             m
  166.             if 'essential' in m[0].prop('src'):
  167.                 self['essential'].add(x)
  168.                 continue
  169.             m
  170.             if not None:
  171.                 raise AssertionError, 'unsupported type'
  172.         
  173.         self.parsed = True
  174.  
  175.     
  176.     def add(self):
  177.         raise NotImplementedError, 'read-only'
  178.  
  179.  
  180.  
  181. class Lifecycle(object):
  182.     
  183.     def __init__(self, xml):
  184.         self.xmldoc = xml[0]
  185.         self.parsed = False
  186.         self.registrant = user(None)
  187.         self.date_registered = None
  188.         self.starter = user(None)
  189.         self.date_started = None
  190.         self.completer = user(None)
  191.         self.date_completed = None
  192.  
  193.     
  194.     def parse(self):
  195.         if self.parsed:
  196.             return True
  197.         rows = self.xmldoc.xpathEval('tr')
  198.         for row in rows:
  199.             if row.xpathEval('th[contains(.,"Registered by")]'):
  200.                 if not not (self.registrant):
  201.                     raise AssertionError
  202.                 self.registrant = _get_user(row, 'td/a')
  203.                 continue
  204.             not (self.registrant)
  205.             if row.xpathEval('th[contains(.,"When")]'):
  206.                 if not not (self.date_registered):
  207.                     raise AssertionError
  208.                 x = _get_content(row, 'td/span/@title')
  209.                 self.date_registered = LPTime(x)
  210.                 continue
  211.             not (self.date_registered)
  212.             if row.xpathEval('th[contains(.,"Started")]'):
  213.                 if not not (self.date_started):
  214.                     raise AssertionError
  215.                 x = _get_content(row, 'td')
  216.                 self.date_started = LPTime(x)
  217.                 continue
  218.             not (self.date_started)
  219.             if row.xpathEval('th[contains(.,"Completed")]'):
  220.                 if not not (self.date_completed):
  221.                     raise AssertionError
  222.                 x = _get_content(row, 'td')
  223.                 self.date_completed = LPTime(x)
  224.                 continue
  225.             not (self.date_completed)
  226.             if row.xpathEval('th[contains(.,"by")]'):
  227.                 i = row.xpathEval('preceding-sibling::tr/th')
  228.                 if not i:
  229.                     raise AssertionError
  230.                 if 'started' in i[-1].content.lower():
  231.                     if not not (self.starter):
  232.                         raise AssertionError
  233.                     self.starter = _get_user(row, 'td/a')
  234.                 elif 'completed' in i[-1].content.lower():
  235.                     if not not (self.completer):
  236.                         raise AssertionError
  237.                     self.completer = _get_user(row, 'td/a')
  238.                 elif not None:
  239.                     raise AssertionError, 'wrong xpath'
  240.                 i
  241.                 continue
  242.             self.parsed
  243.             if not None:
  244.                 raise AssertionError, 'unknown attribute in InfoBox: %s' % row.xpathEval('th').content
  245.         
  246.         self.parsed = True
  247.  
  248.  
  249.  
  250. class BugInfo(LPBugInfo):
  251.     
  252.     def __init__(self, nr, url, summary):
  253.         LPBugInfo.__init__(self, nr, url, None, None, summary, None, False)
  254.  
  255.     
  256.     def __str__(self):
  257.         return '[Bug %s]' % self.url
  258.  
  259.  
  260.  
  261. class RelatedBugs(set):
  262.     
  263.     def __init__(self, xml):
  264.         self.xmldoc = xml
  265.         self.parsed = False
  266.         set.__init__(self)
  267.  
  268.     
  269.     def parse(self):
  270.         if self.parsed:
  271.             return True
  272.         for i in self.xmldoc:
  273.             m = i.xpathEval('a')
  274.             if not m:
  275.                 raise AssertionError
  276.             u = m[0].prop('href')
  277.             nr = int(u.split('/').pop())
  278.             s = m[0].content.split(':').pop()
  279.             summary = s.strip('\n ')
  280.             self.add(BugInfo(nr, u, summary))
  281.         
  282.         self.parsed = True
  283.  
  284.  
  285.  
  286. class Overview(object):
  287.     
  288.     def __init__(self, xml):
  289.         self.xmldoc = xml
  290.         self.parsed = False
  291.  
  292.     
  293.     def parse(self):
  294.         if self.parsed:
  295.             return True
  296.         if not self.xmldoc:
  297.             raise AssertionError
  298.         self.text = self.xmldoc[0].content
  299.         self.parsed = True
  300.  
  301.  
  302.  
  303. class FullSpec(object):
  304.     
  305.     def __init__(self, xml):
  306.         self.xmldoc = xml
  307.         self.parsed = False
  308.  
  309.     
  310.     def parse(self):
  311.         if self.parsed:
  312.             return True
  313.         if not self.xmldoc:
  314.             raise AssertionError
  315.         self.url = self.xmldoc[0].prop('href')
  316.         self.parsed = True
  317.  
  318.  
  319.  
  320. class Mentors(set):
  321.     
  322.     def __init__(self, xml):
  323.         self.xmldoc = xml
  324.         self.parsed = False
  325.         set.__init__(self)
  326.  
  327.     
  328.     def parse(self):
  329.         if self.parsed:
  330.             return True
  331.         for i in self.xmldoc:
  332.             x = user.parse_html_user(i)
  333.             self.add(x)
  334.         
  335.         self.parsed = True
  336.  
  337.  
  338.  
  339. class WhiteBoard(object):
  340.     
  341.     def __init__(self, xml):
  342.         self.xmldoc = xml
  343.         self.parsed = False
  344.         self.text = ''
  345.  
  346.     
  347.     def parse(self):
  348.         if self.parsed:
  349.             return True
  350.         if self.xmldoc:
  351.             self.text = self.xmldoc[0].content
  352.         
  353.         self.parsed = True
  354.  
  355.  
  356.  
  357. class _Request(object):
  358.     
  359.     def __init__(self, user, target, text):
  360.         self.user = user
  361.         self.target = target
  362.         self.text = text
  363.  
  364.     
  365.     def __repr__(self):
  366.         return "<FeedbackRequest from '%s' to '%s'>" % (self.user, self.target)
  367.  
  368.  
  369.  
  370. class FeedbackRequest(list):
  371.     
  372.     def __init__(self, xml):
  373.         self.xmldoc = xml
  374.         self.parsed = False
  375.         list.__init__(self)
  376.  
  377.     
  378.     def parse(self):
  379.         if self.parsed:
  380.             return True
  381.         for i in self.xmldoc:
  382.             m = i.xpathEval('a')
  383.             if not m:
  384.                 raise AssertionError
  385.             r_user = user.parse_html_user(m[0])
  386.             m = i.xpathEval('strong/a')
  387.             if not m:
  388.                 raise AssertionError
  389.             r_target = user.parse_html_user(m[0])
  390.             m = i.xpathEval('div[@style="font-style: italic;"]')
  391.             if not m:
  392.                 raise AssertionError
  393.             r_text = m[0].content
  394.             self.append(_Request(r_user, r_target, r_text))
  395.         
  396.         self.parsed = True
  397.  
  398.  
  399.  
  400. class Blueprint(LPBluePrint):
  401.     
  402.     def __init__(self, url, connection):
  403.         LPBluePrint.__init__(self, url, connection)
  404.         page = self._connection.get(self.url)
  405.         self.xmldoc = libxml2.htmlParseDoc(unicode_for_libxml2(page.text), 'UTF-8')
  406.         self._Blueprint__info_box = InfoBox(self.xmldoc.xpathEval('//table[@class="summary"]/tbody'))
  407.         self._Blueprint__subscribers = Subscribers(self.xmldoc.xpathEval('//div[@id="portlet-subscribers"]/div[@class="portletBody"]//div'))
  408.         self._Blueprint__lifecycle = Lifecycle(self.xmldoc.xpathEval('//div[@id="portlet-lifecycle"]/div/table/tbody'))
  409.         self._Blueprint__related_bugs = RelatedBugs(self.xmldoc.xpathEval('//div[@id="portlet-related-bugs"]/div/ul//li'))
  410.         self._Blueprint__overview = Overview(self.xmldoc.xpathEval('//table[@class="summary"]/following-sibling::p[1]'))
  411.         self._Blueprint__full_spec = FullSpec(self.xmldoc.xpathEval('//table[@class="summary"]/following-sibling::ul[1]/li/a'))
  412.         self._Blueprint__mentors = Mentors(self.xmldoc.xpathEval('//table[@class="summary"]/following-sibling::p[2]//a'))
  413.         self._Blueprint__whiteboard = WhiteBoard(self.xmldoc.xpathEval('//h2[contains(.,"Whiteboard")]/following-sibling::div'))
  414.         self._Blueprint__feedback_request = FeedbackRequest(self.xmldoc.xpathEval('//div[@id="portlet-feedback"]/div/ul//li'))
  415.  
  416.     get_priority = _gen_getter('__info_box.priority')
  417.     get_status = _gen_getter('__info_box.status')
  418.     get_delivery = _gen_getter('__info_box.delivery')
  419.     get_assignee = _gen_getter('__info_box.assignee')
  420.     get_drafter = _gen_getter('__info_box.drafter')
  421.     get_approver = _gen_getter('__info_box.approver')
  422.     get_sprints = _gen_getter('__info_box.sprints')
  423.     get_subscribers = _gen_getter('__subscribers')
  424.     
  425.     def get_subscriptions_category(self, type):
  426.         return self._Blueprint__subscribers.get_subscriptions(type)
  427.  
  428.     get_lifecycle = _gen_getter('__lifecycle')
  429.     get_related_bugs = _gen_getter('__related_bugs')
  430.     get_overview = _gen_getter('__overview.text')
  431.     get_full_spec = _gen_getter('__full_spec.url')
  432.     get_mentors = _gen_getter('__mentors')
  433.     get_whiteboard = _gen_getter('__whiteboard.text')
  434.     get_feedback_request = _gen_getter('__feedback_request')
  435.     
  436.     def get_title(self):
  437.         x = self.xmldoc.xpathEval('//div[@class="main"]')
  438.         if not x:
  439.             raise AssertionError
  440.         return x[0].content
  441.  
  442.     
  443.     def get_spec(self):
  444.         return self.url.split('/').pop()
  445.  
  446.     
  447.     def get_project(self):
  448.         x = self.xmldoc.xpathEval('//div[@class="intro"]')
  449.         if not x:
  450.             raise AssertionError
  451.         return x[0].content.split('Blueprint for').pop().strip()
  452.  
  453.  
  454.